import request from '@/utils/request.js'
import { useTokenStore } from '@/stores/token'

// 文章分类列表查询
export const articleCategoryListService = () => {
    /*
    const tokenStore = useTokenStore()
    return request.get('/category', 
        // 在 Pinia 中定义的响应式数据，都不需要 .value
        { headers: {'Authorization': tokenStore.token} }
    )
    */
    return request.get('/category')
}

// 添加文章分类
export const articleCategoryAddService = (categoryData) => {
    return request.post('/category', categoryData)
}

// 更新文章分类
export const articleCategoryUpdateService = (categoryData) => {
    return request.put('/category', categoryData)
}

// 删除文章分类
export const articleCategoryDeleteService = (id) => {
    return request.delete('/category?id=' + id)
}

// 文章列表查询
export const articleListService = (params) => {
    // queryString 类型的参数传递：{键：参数名}
    return request.get('/article', {params: params})
}

// 新增文章
export const articleAddService = (articleData) => {
    return request.post('/article', articleData)
}

// 修改文章
export const articleUpdateService = (articleData) => {
    return request.put('/article', articleData)
}

// 删除文章
export const articleDeleteService = (id) => {
    return request.delete('/article?id=' + id)
}